const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const htmlPlugin = new HtmlWebpackPlugin({
    template: path.resolve(__dirname, 'index.html'),
    filename: 'index.html' // 复制出来的文件名
});

module.exports = {
    mode: 'development',
    entry: './src/main.ts',// 入口文件
    // 输出
    output: {
        filename: 'index.js',// 编译出来的文件名
        path: path.resolve(__dirname, 'dist'),//编译文件所在目录   
        publicPath: '/dist/',// 静态资源目录,可以设为“编译文件所在目录”, 代码自动编译，网页自动刷新
    },
    // loader 
    module: {
        rules: [
            { test: /\.ts?$/, use: ['ts-loader'], exclude: /(?:node_modules)/, },
        ]
    },
    resolve: {
        modules: ['src', 'node_modules'],
        extensions: ['.js', '.ts']
    },
    plugins: [htmlPlugin],
    devServer: {
        static: {
            directory: path.join(__dirname, ''),
        },
        hot: true,
        compress: true,
        host: 'localhost',
        port: 8080
    }
};
